'''The walking around part of the game. Feel free to improve and work on.
   I'll import all of the NPC's, tilesets and images into a folder in images.
        -Spenser 
'''

''' I just took the code from the block dodger game thing that we did because im lazy and didnt want to
    write it from scratch.
    -S

'''


import pygame
import random
import time


  
    
    
    

playerSpeed     = 6
SCREENWIDTH = 654
SCREENHEIGHT = 375
FPS = 30

WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BLUE  = (0, 255, 0)
RED   = (255, 0, 0)



class Block(pygame.sprite.Sprite):
    
    def __init__(self, color = BLACK):
        pygame.sprite.Sprite.__init__(self)
#        self.image = pygame.image.load()
#        self.image.fill(color)
        self.rect = self.image.get_rect()
        self.dx = 0
        self.dy = 0
        
    def update(self):
        self.rect.move_ip(self.dx, self.dy)
        
class Player(Block):
    
    def __init__(self):
        Block.__init__(self, BLUE)
        
    def update(self):
        Block.update(self)
        if self.rect.x < 0:
            self.rect.x = 0
        elif self.rect.x > SCREENWIDTH - self.rect.width:
            self.rect.x = SCREENWIDTH - self.rect.width
        if self.rect.y < 0:
            self.rect.y = 0
        elif self.rect.y > SCREENHEIGHT - self.rect.height:
            self.rect.y = SCREENHEIGHT - self.rect.height


pygame.init()

screen = pygame.display.set_mode([SCREENWIDTH, SCREENHEIGHT])

block_list = pygame.sprite.Group()
all_sprites_list = pygame.sprite.Group()  
    
    
    
player = Player()
all_sprites_list.add(player)

font = pygame.font.SysFont("Arial", 30, False, False)

clock = pygame.time.Clock()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                player.dy -= playerSpeed
            elif event.key == pygame.K_DOWN:
                player.dy += playerSpeed
            elif event.key == pygame.K_LEFT:
                player.dx -= playerSpeed
            elif event.key == pygame.K_RIGHT:
                player.dx += playerSpeed
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_UP:
                player.dy -= -playerSpeed
            elif event.key == pygame.K_DOWN:
                player.dy += -playerSpeed
            elif event.key == pygame.K_LEFT:
                player.dx -= -playerSpeed
            elif event.key == pygame.K_RIGHT:
                player.dx += -playerSpeed
    
    screen.fill(WHITE)
    all_sprites_list.update()
    all_sprites_list.draw(screen)
    pygame.display.flip()  # similar to pygame.display.update()
    

        
        
    clock.tick(FPS)
    